<template>
	<view class="contain ">
		<view class="title">
			<view style="overflow: hidden;width: 160rpx; height: 160rpx;border-radius: 40rpx;">
				<image src="https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/WechatIMG2024121214101.jpg" mode=""
					style="width: 160rpx; height: 160rpx;"></image>
			</view>
			<view style="margin-left: 40rpx;">
				找活招工
				<br />
				就到天下工人
			</view>

		</view>
		<view class="tip">
			邀您注册APP
		</view>
		<view class="input">
			<u--input placeholder="请填写您的电话号" border="surround" v-model="loginFrom.phone" shape='circle'
				customStyle='background-color:#ffffff'></u--input>
		</view>
		<view style="width: 80%;margin: auto;margin-top: 40rpx;">
			<u-input placeholder="填写验证码" border="surround" v-model="loginFrom.code" shape='circle'
				customStyle='background-color:#ffffff'>
				<template slot="suffix">
					<u-code ref="uCode" @change="codeChange" :seconds="seconds"></u-code>
					<view @tap="getCode" style="color: #555555;font-size: 28rpx; border-left: 1px #c0c4cc solid;padding-left: 15rpx;">
						{{tips}}
					</view>
					<!-- <u-button @tap="getCode"  type="success" size="mini">{{tips}}</u-button> -->
				</template>
			</u-input>
		</view>
		<!-- <view class="xieyi dis-row" style="width: 80%;margin: auto;">
			<view class="checkbox" >
				<checkbox-group @change="checkRideo">
					<label style="padding-right: 0;">
						<checkbox style="transform:scale(0.7)" value="cn" :checked="isgreen" />
					</label>
				</checkbox-group>
			</view>
			同意
			<text @click="openDoc(1)">《用户协议》</text>和
			<text @click="openDoc(2)">《隐私协议》</text>
		</view> -->
		<view class="btn">
			<u-button type="primary" text="提交" @click="submit()"></u-button>
		</view>
		<u-overlay :show="showuploadImage">
				<view class="autloading" style="width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;">
					<u-loading-icon :show="showuploadImage" color="white"></u-loading-icon>
				</view>
				
		</u-overlay>
		<!-- <button type="primary" open-type="launchApp" binderror="launchAppError" style="border-radius: 40rpx;width: 40%;position: relative;top: 300rpx">前往APP</button> -->
	</view>
	
</template>

<script>
	import Index from '@/common/index-model.js'
	let index = new Index();
	let that = null;
	export default {
		data() {
			return {
				tips: '',
				seconds: 60,
				loginFrom: {
					phone: '',
					code: ''
				},
				invite: '',
				showuploadImage:false
			}
		},
		onLoad(opt) {
			if (opt.id) {
				console.log(opt.id)
				this.invite = opt.id
			}
		},
		methods: {
			launchAppError(e) {
				// 处理错误事件的逻辑
				console.error('Error launching app:', e);
				// 可以在这里添加错误处理逻辑，比如显示一个错误提示
				uni.showToast({
					title: '无法返回App，请手动打开',
					icon: 'none'
				});
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (!index.is_phone_number(this.loginFrom.phone)) {
					index.show_tips('请输入正确的手机号码')
					return
				}
				if (this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					let sendCode = {
						"mobile": this.loginFrom.phone,
						"smsmode": 4
					}
					// this.getRegistrationID();
					index.getPublicMember(sendCode, 'sys/clientSms', 'post', res => {
						if (res.data.success) {
							uni.hideLoading();
							uni.$u.toast('验证码已发送');
							this.$refs.uCode.start();
						} else {
							index.show_tips(res.data.message)
							return false
						}
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			
			submit() {
				this.showuploadImage = true
				console.log("提交", this.loginFrom, this.invite)
				let subdata = {
					"phone": this.loginFrom.phone,
					"code": this.loginFrom.code,
					"pid": this.invite
				}
				index.getPublicMember(subdata, 'sys/mobilePreRegister', 'post', res => {
					if (res.data.success) {
						this.showuploadImage = false
						index.show_tips(res.data.message)
						setTimeout(() => {
							index.switch_tab('../index/index')
						}, 2000)
					} else {
						this.showuploadImage = false
						index.show_tips(res.data.message)
						return false
					}
				})
			}
		}
	}
</script>

<style>
	@import url("@/static/css/publics.css");
	@import url("@/static/css/login.css");
</style>
<style scoped>
	page {
		width: 100%;
		height: 100%;
		background-color: #FfF3F3;
	}

	.title {
		font-size: 60rpx;
		color: #FFFFFF;
		margin: auto;
		margin-top: 200rpx;
		width: 80%;
		display: flex;
		align-items: center;
	}

	.tip {
		font-size: 30rpx;
		color: #555555;
		margin: auto;
		margin-top: 200rpx;
		width: 80%;
	}

	.contain {
		background: linear-gradient(180deg, #8DC0FF 0%, rgba(255,255,255,0.00) 70%);
		/* height: 100vh; */
		/* background-image: url('https://xgr.oss-cn-hangzhou.aliyuncs.com/icon/WechatIMG2024121211541.jpg'); */
		background-size: 100% 100%;
		overflow-x: hidden;
		overflow-y: hidden;
	}

	.input {
		margin: auto;
		margin-top: 20rpx;
		width: 80%;
	}

	.btn {
		width: 80%;
		margin: auto;
		margin-top: 40rpx;

	}
</style>